﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using SQLExecute;

public class Common
{
    public static string strConnect = ConfigurationSettings.AppSettings["ConnectString"];
    DataSet ds;
    static DataTable[] dt=new DataTable[6];
	public Common()
	{
		
	}
  
    public DataSet Select_Common()
    {
        ds = SqlHelper.ExecuteDataset(Common.strConnect, "Select_Common");

        return ds;
    }

    static public string Convert_DDMMYYYY_To_MMDDYYY(string s)
    {

        string month, day, year;

        int n1 = s.IndexOf("/", 0);

        day = s.Substring(0, n1);

        int n2 = s.IndexOf("/", n1 + 1);
        month = s.Substring(n1 + 1, n2 - (n1 + 1));

        year = s.Substring(s.Length - 4, 4);
        
        s = month + "/" + day + "/" + year;
        return s;
    }
    static public string Convert_MMDDYYYY_To_DDMMYYY(string s)
    {

        string month, day, year;

        int n1 = s.IndexOf("/", 0);

        month = s.Substring(0, n1);

        int n2 = s.IndexOf("/", n1 + 1);
        day = s.Substring(n1 + 1, n2 - (n1 + 1));

        year = s.Substring(s.Length - 4, 4);

        //n = s.IndexOf("/", n);
        //month=s.Substring(n+1,

        s = day + "/" + month + "/" + year;
        return s;
    }
    static public string Split_Number_Tele(string str)
    {
        string s = string.Empty;

        if (str.Length == 10)
        {
            s = str.Substring(0, 4) + " ";
            s += str.Substring(4, 3) + " ";
            s += str.Substring(str.Length - 3, 3);
        }

        return s;

    }
    public void InitCombo(DropDownList cbPhongBan,int groupid,int phongbanid)
    {
        string sql=string.Empty;
        if (groupid == 2)
                sql = "select * from tbl_phongban where id='"+phongbanid+"' order by phongban asc";
        else if (groupid == 3)
                sql = "select * from tbl_phongban order by phongban asc";

        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            cbPhongBan.DataSource = ds;
            cbPhongBan.DataTextField = "phongban";
            cbPhongBan.DataValueField = "id";
            cbPhongBan.DataBind();
            if (groupid == 3)
            {
                cbPhongBan.Items.Insert(0, new ListItem("Choose one", "0"));
                cbPhongBan.SelectedIndex = 0;
            }
            else if (groupid == 2)
                cbPhongBan.SelectedIndex = 0;
        }
    }
    

}
